public class Str {
    static String trim(String str){
        int i = 0,j=str.length();
        while (str.charAt(i)==' '){
            i++;
        }
        while (str.charAt(j-1)==' '){
            j--;
        }
        return str.substring(i,j);
    }
    static String trim(String str,int i,int j){
        String rts=str.substring(0,i);
        for (int k=j;k>=i;k--){
            rts+=str.charAt(k);
        }
        rts+=str.substring(j+1,str.length());
        return rts;
    }
    static int Nn(String str,String s){
        int nu=0;
        for (int i=0;i<=str.length()-s.length();i++){
            if (str.charAt(i)==s.charAt(0)){
                    for (int j=0;j<s.length();j++){
                        if (str.charAt(i+j)!=s.charAt(j)){
                            break;
                        }
                        if (j==s.length()-1&&str.charAt(i+j)==s.charAt(j)){
                            nu++;
                        }
                    }
            }
        }
        return nu;
    }
    public static void main(String[] args) {
        String a = "       asd fivv           ";
        a=trim(a);
        System.out.println(a.length());
        System.out.println(trim(a,2,4));
        System.out.println(Nn(a,"vv")+Nn(a,"v"));
    }
}
